<template>
	<view class="contentss" :style="$theme.pageStyle">

		<view class="content">
			<view class="details">
				<view>
					<view class="produce_list">
						<view class="view_box">
							<view class="goods-card">
								<view class="item fadeInUp">
									<view class="img">
										<u-image width="100%" height="165px" border-radius="10px"
											:src="GoodsInfo.image"></u-image>
									</view>
									<view class="item_cont">
										<view style="display: flex;justify-content: space-between;">
											<view class="title u-line-2">
												{{GoodsInfo.name}}
											</view>
											<view class="title u-line-2" style="font-size: 12px;" v-if="GoodsInfo.spec_type == 2">
												已选择 <span style="color: #ffbc25;"> {{specSelect.sku_value}}</span>
											</view>
										</view>
										<view>
											<view class="" style="display: flex;">
												<view class="tags">
													<text class="tags_style"
														style="background: #3fda9b;">{{GoodsInfo.departureDuration}}</text>
												</view>
												<view class="tags">
													<text class="tags_style"
														style="background: #ffbc25;">{{GoodsInfo.age}}</text>
												</view>
												<view class="tags">
													<text class="tags_style"
														style="background: #dd524d;">{{GoodsInfo.destination}}</text>
												</view>
											</view>

										</view>
										<view class="btm" style="display: flex;justify-content: space-between;">
											<view class="price">
												¥ {{specSelect.price}}
											</view>
											<view class="user">
												<view class="tips">
													<span class="stit">
														{{GoodsInfo.price_desc}}
													</span>
												</view>
											</view>
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>


			<view class="mt-20 bg--w111-fff rd-16rpx pt-32 pr-24 pl-24 pb-32">
				<view class="cell flex-between-center" @tap='couponTap'>
					<text class="text--w111-333 fs-28">优惠券</text>
					<view>
						<text class="text--w111-333 fs-28">{{couponTitle}}</text>
						<uni-icons type="right" size="12"></uni-icons>
					</view>
				</view>
			</view>


			<view class="rd-24rpx bg--w111-fff mt-20 py-16">
				<view class="px-20 flex-between-center">
					<view>
						<text class="text--w111-333 fs-30 fw-500">学生信息</text>
					</view>
					<view class="flex-y-center">
						<uni-icons type="right" size="12"></uni-icons>
					</view>
				</view>
				<view class="leaveMessage">
					<view class="list b-b">
						<view class="wrapper">
							<view class="address-box">
								<text class="address">{{Card.student_name}}</text>
							</view>
							<view class="u-box">
								<text class="mobile">{{Card.idcode}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>

			<view style="background: #fff;margin-top: 10px;border-radius: 8px;" v-if="havevipcard">
				<cl-cell-group title="使用课卡支付" :titleStyle="{'margin-top': '50rpx'}" style="padding: 0px;">
					<cl-cell :title="vipcard.name" :isLink="false" :border="false">
						<template #icon>
							<image :src="vipcard.picture" mode="widthFix" style="width: 80px;height: 50px;border-radius: 8px;"></image>
						</template>
						<template #value>
							<switch :checked="checked" style="transform:scale(0.8)" @change="changechecked" />
						</template>
						<template #label>
							<span v-if="vipcard.usable == 0">无次数限制</span>
							<span v-else>剩余可用 {{user_vipcard.usable}} 次</span>
						</template>
					</cl-cell>
				</cl-cell-group>
			</view>


			<view class="details" style="padding-bottom: 10px;margin-top: 10px;height: 25px;line-height: 25px;">
				<view style="display: flex;margin-top: 20px;">
					<label class="radio">
						<checkbox value="" v-bind:checked="xychecked" @click="kekacheck()" style="transform:scale(0.7);" />
					</label>
					我同意<span style="color: var(--color-primary);" @click="toxieyi()">《活动参营协议》</span>
				</view>
			</view>


			<view class="payment_box">
				<view class="pay_btn" @click="payer()" v-if="carstatus == 0">立即支付</view>
				<view class="pay_btn" @click="cardpay()" v-else>课卡支付</view>
			</view>
		</view>


	</view>
</template>

<script>
	import $H from '@/common/js/request.js'
	export default {
		components: {},
		data() {
			return {
				lists: [], //所有地址列表
				payList: uni.getStorageSync('paytype'),
				order_list: '', //商品数据
				shop_data: '', //商品详情数组
				address_data: [], //地址数组
				address: 0, //地址数组
				remark: '无', //内容
				goodsid: '', //商品id
				paytype: 'wechat',
				addresid: 0,
				shopList: [],
				addid: 0,
				addname: '',
				addphone: '',
				addprovince: '',
				addcity: '',
				addarea: '',
				addaddress: '',
				status: 1,
				Card: {},
				checked: false,
				xychecked: false,
				havevipcard: false,
				active: 0,
				GoodsInfo: {},
				card: {},
				couponTitle: '无优惠券', //优惠券
				coupon_price: 0, //优惠券抵扣金额
				vipcard: {},
				user_vipcard: {},
				carstatus: 0,
				card_id: 0,
				coupon_id: 0,
				spec_type: 0,
				spec_id: 0,
				specSelect: uni.getStorageSync('specSelect'),

			}
		},
		onLoad(opt) {
			this.card_id = opt.card_id
			this.getGoodsDetail()
			this.getCard()
			// this.code = opt.order || '';
			//this.loadorder();
			this.getvipcard();
		},
		onShow() {
			//this.getvipcard();
		},
		methods: {
			kekacheck(){
				if(!this.xychecked){
					this.xychecked = true
				}else{
					this.xychecked = false
				}
			},
			async getGoodsDetail() {
				try {
					const res = await $H.post('goods/detail', {
						id: uni.getStorageSync('goods_id')
					}, {
						token: false
					});
					this.GoodsInfo = res.data
					this.spec_type = res.data.spec_type
					if(this.spec_type == 2){
						this.spec_id = this.specSelect.id
					}
				} catch (error) {

				} finally {
					//uni.hideLoading();
				}
			},
			async getCard() {
				try {
					const res = await $H.post('user/showcard', {
						id: this.card_id
					}, {
						token: true
					});
					this.Card = res.data
				} catch (error) {

				} finally {
					//uni.hideLoading();
				}
			},
			toxieyi() {
				uni.navigateTo({
					url: '/pages/content/index?name=canyingxieyi'
				})
			},
			getvipcard() {
				$H.post('card/findmycard', {
					id: uni.getStorageSync('goods_id')
				}, {
					token: true
				}).then(res => {
					if (res.code == 1) {
						this.vipcard = res.data.vipCardInfo
						this.user_vipcard = res.data.userCardInfo
						this.havevipcard = true
					}else{
						this.havevipcard = false
					}
				})
			},

			jump(url) {
				uni.navigateTo({
					url: url
				})
			},
			changechecked(e) {
				if (e.detail.value) {
					this.carstatus = 1
				} else {
					this.carstatus = 0
				}
			},
			cardpay() {
				if (!this.xychecked) {
					return uni.showToast({
						title: '您还没同意协议！',
						icon: 'none'
					})
				}
				$H.post('order/CardOrder', {
					'id': uni.getStorageSync('goods_id'),
					'card_id': this.user_vipcard.id,
					'coupon_id': this.coupon_id,
					'order_amount': this.specSelect.price,
					'spec_type': this.spec_type,
					'spec_id': this.spec_id,
					'user_card_id': this.card_id
				}, {
					token: true
				}).then(res => {
					if (res.code == 1) {
						uni.showToast({
							icon: 'none',
							title: res.msg
						});
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/order/index'
							})
						}, 400)
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						});
					}
				})
			},
			// 提交订单
			payer() {
				if (!this.xychecked) {
					return uni.showToast({
						title: '您还没同意协议！',
						icon: 'none'
					})
				}

				$H.post('v1.we_pay/orderpay', {
					'order_no': this.code,
				}, {
					token: true
				}).then(res => {
					if (res.code == 200) {

						uni.requestPayment({
							provider: 'wxpay',
							appId: res.data.options.appId,
							timeStamp: res.data.options.timeStamp,
							nonceStr: res.data.options.nonceStr,
							package: res.data.options.package,
							signType: 'MD5',
							paySign: res.data.options.paySign,
							success: function(res) {
								//跳转到会话页面

								setTimeout(() => {

									uni.switchTab({
										url: '/pages/order/index'
									})

								}, 400)

							},
							fail: function(err) {
								uni.showToast({
									title: '支付失败',
									duration: 2000
								});
							}
						})

					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						});
					}

				})
			}
		}

	}
</script>

<style lang="scss" scoped>
	page {
		width: 100%;
		height: 100%;
		background: rgb(245, 245, 245);

	}

	.contentss {
		background: linear-gradient(180deg, var(--color-primary) 0%, var(--color-primary-light-3) 52%, rgba(233, 51, 35, 0) 100%);
	}

	.content {
		padding: 15px;
		width: 100%;
		height: 100%;
		box-sizing: border-box;
		padding-bottom: 150rpx;

	}

	.top-icon {
		float: right;
		margin: 10upx 0;
		color: #999999;
		line-height: 50rpx;
	}

	.li-frist {
		width: 100%;
		height: 66rpx;
		line-height: 66rpx;
		font-size: 24rpx;
		color: #333333;
		text-indent: 20upx;
		/* display: flex; */
		align-items: center;
		justify-content: flex-start;
	}

	.h1 {
		color: #333333;
		font-size: 26rpx;
		font-weight: bold;
	}

	.select {
		margin-left: 35rpx;
	}

	.li {
		width: 100%;
		/* height: 140rpx; */
		box-sizing: border-box;
		padding-bottom: 20rpx;
		display: flex;
		align-items: flex-start;
		justify-content: space-around;
		flex-direction: column;
	}

	.li:last-of-type {
		margin-bottom: 0;
	}

	.li_one {
		animation: hh 1s linear;
	}

	@keyframes hh {
		from {
			height: 100%;
		}

		to {
			height: 183rpx;
		}
	}

	.li_data {
		padding: 0 20upx;
		margin-top: 10upx;
		line-height: 40upx;
		display: flex;
		width: 100%;
		color: #333333;
		font-size: 28rpx;
	}

	.li-left {
		width: 25%;
	}

	.li-right {
		width: 75%;
	}

	.li_datas {
		width: 100%;
		margin-left: 80rpx;
		display: flex;
		justify-content: flex-start;
		color: #333333;
		font-size: 24rpx;
		position: relative;
	}

	.tick {
		width: 40rpx;
		height: 40rpx;
		position: absolute;
		top: 0;
		left: -60rpx;
	}

	.tick image {
		width: 100%;
		height: 100%;
	}

	.li_data text {
		margin-left: 10rpx;
	}

	.new_address {
		width: 100%;
		padding-left: 160rpx;
		color: #333333;
		font-size: 28rpx;
		text-align: left;
	}

	.details {
		width: 100%;
		box-sizing: border-box;
		border-radius: 8px;
	}

	.details_title {
		width: 100%;
		height: 68rpx;
		line-height: 68rpx;
		box-sizing: border-box;
		padding: 0 32rpx;
		color: #333333;
		font-size: 30rpx;
		font-weight: bold;
		background: #F2F2F2;
	}

	.details_content {
		width: 100%;
		box-sizing: border-box;
	}

	.shop {
		width: 100%;
		height: 183rpx;
		box-sizing: border-box;
		padding-left: 30rpx;
		border-bottom: 2rpx solid #F2F2F2;
		display: flex;
		justify-content: space-between;
		align-items: center;
		background: #FFFFFF;
	}

	.shop .img {
		width: 124rpx;
		height: 124rpx;
		overflow: hidden;
	}

	.img image {
		width: 124rpx;
		height: 124rpx;
		border-radius: 10rpx;
	}

	.shop_title {
		width: 350rpx;
		height: 124rpx;
		color: #333333;
		font-size: 24rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		box-sizing: border-box;
		padding: 10rpx 0;
	}

	.spend {
		min-width: 150rpx;
		max-height: 180rpx;
		box-sizing: border-box;
		padding-right: 20rpx;
		color: #333333;
		font-size: 30rpx;
		font-weight: bold;
		text-align: right;
	}

	.spend text {
		color: #333333;
		font-size: 24rpx;
		font-weight: 500;
	}

	.shop_price {
		width: 100%;
		height: 183rpx;
		box-sizing: border-box;
		padding: 0 57rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: flex-start;
		border-bottom: 2rpx solid #F2F2F2;
	}

	.shop_price view {
		width: 100%;
		color: #333333;
		font-size: 28rpx;
	}

	.shop_price text {
		padding-left: 10rpx;
		color: #F53F3F;
		font-size: 28rpx;
	}

	.shop_price view:last-of-type text {
		color: #48BA9D;
	}

	.message {
		width: 100%;
		height: 113rpx;
		box-sizing: border-box;
		padding: 24rpx 30rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.message input {
		width: 100%;
		height: 66rpx;
		padding: 0 20rpx;
		font-size: 24rpx;
		border: 2rpx solid #cccccc;
	}

	.uni-input-placeholder {
		color: #999999;
		font-size: 24rpx;
	}

	.price_li {
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
		color: #333333;
		font-size: 30rpx;
	}

	.pay_way {
		width: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		background: #FFFFFF;
		border-radius: 8px;
	}

	.pay_title {
		width: 100%;
		height: 68rpx;
		line-height: 70rpx;
		padding: 10rpx 0px 10rpx 5px;
		color: #333333;
		font-size: 32rpx;
		font-weight: bold;
		display: flex;
		align-items: center;
		justify-content: flex-start;
		border-bottom: 1rpx solid #F2F2F2;
	}

	.pay_list {
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.pay_li {
		width: 100%;
		height: 88rpx;
		box-sizing: border-box;
		padding: 0 44rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		color: #333333;
		font-size: 30rpx;
		font-weight: bold;
		// border-bottom: 2rpx solid #F2F2F2;
	}

	.pay_text {
		display: flex;

	}

	.pay_text image {
		width: 60rpx;
		height: 60rpx;
	}

	.pay_text text {
		padding-left: 20rpx;
	}

	.pay_img {
		height: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.pay_img image {
		width: 40rpx;
		height: 40rpx;
	}

	.payment {
		width: 100%;
		height: 100rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		background: #FFFFFF;
		border-top: 2rpx solid #F2F2F2;
	}

	.payment_text {
		height: 100rpx;
		box-sizing: border-box;
		padding: 0 30rpx;
		color: #FFF;
		font-size: 30rpx;
		font-weight: bold;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.payment_box {
		width: 100%;
		height: 120rpx;
		position: fixed;
		bottom: 20px;
		left: 0;
		z-index: 105;
	}

	.pay_btn {
		margin: 10px;
		height: 96rpx;
		color: #FFFFFF;
		display: flex;
		font-size: 40upx;
		font-weight: 500;
		justify-content: center;
		align-items: center;
		border-radius: 16rpx;
		background: linear-gradient(90deg, var(--color-primary) 0%, var(--color-primary-light-3) 100%);
	}

	.pay_top {
		width: 100%;
		height: 90rpx;
		box-sizing: border-box;
		padding: 0 20rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.pay_top view {
		width: 200rpx;
	}

	.box_title {
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 40rpx;
		font-weight: bold;
	}

	.close_box image {
		width: 30rpx;
		height: 30rpx;
	}

	.pay_content {
		width: 100%;
	}

	.pay_price {
		width: 100%;
		height: 150rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 30px;
	}

	.pay_name {
		width: 100%;
		height: 90rpx;
		box-sizing: border-box;
		padding: 0 30rpx;
		font-size: 30rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-top: 2rpx solid #EEEEEE;
		border-bottom: 2rpx solid #EEEEEE;
	}



	.top-icon {
		color: #F53F3F;
	}






	.produce_list {
		// margin-bottom: 40px;
	}

	.view_box {
		// width: 100%;
		// display: flex;
		// flex-wrap: wrap;
		// justify-content: flex-start;
		// // padding: 0 20upx;
		// box-sizing: border-box;
	}


	.goods-card .item {
		background-size: 190px 233px;
		border-radius: 10px;
		overflow: hidden;
		// box-shadow: 0 1px 12px 1px #f5eaea;
		background-color: #fff;
		margin-bottom: 15px;
	}

	.goods-card .item .img {
		position: relative;
		min-height: 175px;
	}

	.goods-card .item .img .status {
		display: flex;
		align-items: center;
		position: absolute;
		left: 17px;
		top: 26px;
		padding: 4px 6px;
		background: #000;
		box-sizing: border-box;
		padding: 2px 10px;
		height: 26px;
		opacity: .8;
		border-radius: 26px;
		font-size: 12px;
		font-weight: 600;
		color: #fff;
	}

	.tags_style {
		margin-right: 5px;
		color: rgb(255, 255, 255);
		font-size: 12px;
		padding: 3px;
		border-radius: 2px 0px 0px 2px;
	}

	.goods-card .item .item_cont {
		border-radius: 0 0 30px 30px;
		padding: 6px 21px 15px 14px;
	}

	.goods-card .item .item_cont .title {
		font-size: 16px;
		font-weight: 600;
		color: #000;
		line-height: 23px;
		margin-bottom: 9px;
	}

	.goods-card .item .item_cont .btm {
		// display: flex;
		// align-items: center;
		// justify-content: space-between;
		margin-top: 11px;
	}

	.goods-card .item .item_cont .btm .user {
		// display: flex;
		// align-items: center;
	}

	.goods-card .item .item_cont .btm .user text {
		margin-left: 6px;
		font-size: 12px;
		font-weight: 400;
		color: #222;
	}

	.goods-card .item .item_cont .btm .price {
		font-size: 20px;
		font-weight: 900;
		color: #dd524d;
		line-height: 28px;
	}


	.tips .stit {
		font-size: 10px;
		color: #dd524d;
		line-height: 14px;
		font-weight: bold;
	}



	.list {
		margin: 10px;
		padding: 10px;
		border-radius: 10px;
		display: flex;
		align-items: center;
		background: #fff;
		position: relative;
		background: #FFFFFF;
		/* padding-left: 20upx; */
		border: 2upx solid var(--color-primary);
		flex: 1;

	}

	.selected {
		border: 2upx solid var(--color-primary);
		box-shadow: 0 0 4upx var(--color-primary);
	}


	.moren {
		position: absolute;
		right: 0px;
		top: 0px;
		background: #FFE9C2;
		border-radius: 0px 12px 0px 12px;
		width: 40px;
		text-align: center;
		font-size: 10px;
		color: #C66125;
	}

	.wrapper {
		display: flex;
		flex-direction: column;
		flex: 1;
	}

	.address-box {
		display: flex;
		align-items: center;

		.address {
			padding-right: 10upx;
			font-size: 30upx;
			color: #303133;
		}
	}

	.u-box {
		font-size: 28upx;
		color: #909399;

		.name {
			margin-right: 30upx;
		}
	}

	.icon-bianji {
		display: flex;
		align-items: center;
		height: 80upx;
		font-size: 40upx;
		color: #909399;
		padding-left: 30upx;
	}
</style>